package com.lantosec.hmrp.modules.eval.controller;


import com.lantosec.hmrp.core.log.ControllerLog;
import com.lantosec.hmrp.core.log.LogType;
import org.springframework.web.bind.annotation.RequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.lantosec.hmrp.core.kit.Result;
import com.lantosec.hmrp.modules.eval.entity.EvalApply;
import com.lantosec.hmrp.modules.eval.service.IEvalApplyService;
import com.lantosec.hmrp.modules.eval.vo.EvalApplyVO;

import java.util.Arrays;
import java.util.List;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.RestController;
import com.lantosec.hmrp.core.mvc.BaseController;

/**
 *
 * 奖惩申报 控制器
 *
 * @author AutoCode
 * @since 2020-06-23
 */
@Api(value = "奖惩申报控制器", tags = "奖惩申报控制器")
@RestController
@RequestMapping("/eval/apply")
@Log4j2
public class EvalApplyController extends BaseController {
    @Autowired
    private IEvalApplyService service;

    @PostMapping("createEvalApplyUser")
    @ControllerLog(name = "新增奖惩申报(个人我的)", type = LogType.add)
    @ApiOperation(value = "新增奖惩申报(个人我的)")
    public Result<Integer> createEvalApplyUser(@ApiParam(value = "奖惩申报VO对象", required = true) @RequestBody @Validated EvalApplyVO vo){
        service.saveEvalApply(vo);
        return Result.ok();
    }

    @PostMapping("createEvalApplyDept")
    @ControllerLog(name = "新增奖惩申报(科室人员)", type = LogType.add)
    @ApiOperation(value = "新增奖惩申报(科室人员)")
    public Result<Integer> createEvalApplyDept(@ApiParam(value = "奖惩申报VO对象", required = true) @RequestBody @Validated EvalApplyVO vo){
        service.saveEvalApply(vo);
        return Result.ok();
    }

    @PostMapping("createEvalApplyAll")
    @ControllerLog(name = "新增奖惩申报(全院人员)", type = LogType.add)
    @ApiOperation(value = "新增奖惩申报(全院人员)")
    public Result<Integer> createEvalApplyAll(@ApiParam(value = "奖惩申报VO对象", required = true) @RequestBody @Validated EvalApplyVO vo){
        service.saveEvalApply(vo);
        return Result.ok();
    }

    @PostMapping("createEvalApplyDepts")
    @ControllerLog(name = "新增奖惩申报(本科室)", type = LogType.add)
    @ApiOperation(value = "新增奖惩申报(本科室)")
    public Result<Integer> createEvalApplyDepts(@ApiParam(value = "奖惩申报VO对象", required = true) @RequestBody @Validated EvalApplyVO vo){
        service.saveEvalApply(vo);
        return Result.ok();
    }

    @PostMapping("createEvalApplyAlls")
    @ControllerLog(name = "新增奖惩申报(全院科室)", type = LogType.add)
    @ApiOperation(value = "新增奖惩申报(全院科室)")
    public Result<Integer> createEvalApplyAlls(@ApiParam(value = "奖惩申报VO对象", required = true) @RequestBody @Validated EvalApplyVO vo){
        service.saveEvalApply(vo);
        return Result.ok();
    }

    @PutMapping("update")
    @ControllerLog(name = "修改奖惩申报", type = LogType.update)
    @ApiOperation(value = "修改数据")
    public Result<Void> update(@ApiParam(value = "奖惩申报VO对象", required = true) @RequestBody EvalApplyVO vo){
        EvalApply entity = vo.convertToEntity();
        service.updateById(entity);
        return Result.ok();
    }

    @DeleteMapping(value = "delete/{ids}")
    @ControllerLog(name = "逻辑删除奖惩申报", type = LogType.delete)
    @ApiOperation("逻辑删除")
    public Result<Void> delete(@ApiParam(value = "ID列表,用逗号分隔", required = true) @PathVariable(name="ids") String ids){
        if(StringUtils.isNotEmpty(ids)){
            service.removeByIds(Arrays.asList(ids.split(",")));
        }
        return Result.ok();
    }
}
